package com.openbravo.data.gui;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.ComparatorCreator;
import com.openbravo.data.loader.LocalRes;
import com.openbravo.data.loader.Vectorer;
import com.openbravo.data.user.BrowsableEditableData;
import com.openbravo.data.user.BrowseListener;
import com.openbravo.data.user.StateListener;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Comparator;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSeparator;

public class JNavigator extends JPanel
  implements BrowseListener, StateListener
{
  public static final int BUTTONS_ALL = 0;
  public static final int BUTTONS_NONAVIGATE = 1;
  protected BrowsableEditableData m_bd;
  protected ComparatorCreator m_cc;
  protected FindInfo m_LastFindInfo;
  private JButton jbtnFind = null;
  private JButton jbtnSort = null;
  private JButton jbtnFirst = null;
  private JButton jbtnLast = null;
  private JButton jbtnNext = null;
  private JButton jbtnPrev = null;
  private JButton jbtnRefresh = null;
  private JButton jbtnReload = null;

  public JNavigator(BrowsableEditableData paramBrowsableEditableData, Vectorer paramVectorer, ComparatorCreator paramComparatorCreator, int paramInt)
  {
    initComponents();
    if (paramInt == 0)
    {
      this.jbtnFirst = new JButton();
      this.jbtnFirst.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/2leftarrow.png")));
      this.jbtnFirst.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnFirst.setFocusPainted(false);
      this.jbtnFirst.setFocusable(false);
      this.jbtnFirst.setRequestFocusEnabled(false);
      this.jbtnFirst.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnFirstActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnFirst);
    }
    if (paramInt == 0)
    {
      this.jbtnPrev = new JButton();
      this.jbtnPrev.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1leftarrow.png")));
      this.jbtnPrev.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnPrev.setFocusPainted(false);
      this.jbtnPrev.setFocusable(false);
      this.jbtnPrev.setRequestFocusEnabled(false);
      this.jbtnPrev.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnPrevActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnPrev);
    }
    this.jbtnRefresh = new JButton();
    this.jbtnRefresh.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1downarrow.png")));
    this.jbtnRefresh.setMargin(new Insets(2, 8, 2, 8));
    this.jbtnRefresh.setFocusPainted(false);
    this.jbtnRefresh.setFocusable(false);
    this.jbtnRefresh.setRequestFocusEnabled(false);
    this.jbtnRefresh.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JNavigator.this.jbtnRefreshActionPerformed(paramActionEvent);
      }
    });
    add(this.jbtnRefresh);
    if (paramInt == 0)
    {
      this.jbtnNext = new JButton();
      this.jbtnNext.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1rightarrow.png")));
      this.jbtnNext.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnNext.setFocusPainted(false);
      this.jbtnNext.setFocusable(false);
      this.jbtnNext.setRequestFocusEnabled(false);
      this.jbtnNext.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnNextActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnNext);
    }
    if (paramInt == 0)
    {
      this.jbtnLast = new JButton();
      this.jbtnLast.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/2rightarrow.png")));
      this.jbtnLast.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnLast.setFocusPainted(false);
      this.jbtnLast.setFocusable(false);
      this.jbtnLast.setRequestFocusEnabled(false);
      this.jbtnLast.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnLastActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnLast);
    }
    add(new JSeparator());
    if (paramBrowsableEditableData.canLoadData())
    {
      this.jbtnReload = new JButton();
      this.jbtnReload.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/reload.png")));
      this.jbtnReload.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnReload.setFocusPainted(false);
      this.jbtnReload.setFocusable(false);
      this.jbtnReload.setRequestFocusEnabled(false);
      this.jbtnReload.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnReloadActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnReload);
      add(new JSeparator());
    }
    if (paramVectorer == null)
    {
      this.m_LastFindInfo = null;
    }
    else
    {
      this.m_LastFindInfo = new FindInfo(paramVectorer);
      this.jbtnFind = new JButton();
      this.jbtnFind.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/search.png")));
      this.jbtnFind.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnFind.setFocusPainted(false);
      this.jbtnFind.setFocusable(false);
      this.jbtnFind.setRequestFocusEnabled(false);
      this.jbtnFind.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnFindActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnFind);
    }
    this.m_cc = paramComparatorCreator;
    if (this.m_cc != null)
    {
      this.jbtnSort = new JButton();
      this.jbtnSort.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/sort_incr.png")));
      this.jbtnSort.setMargin(new Insets(2, 8, 2, 8));
      this.jbtnSort.setFocusPainted(false);
      this.jbtnSort.setFocusable(false);
      this.jbtnSort.setRequestFocusEnabled(false);
      this.jbtnSort.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
          JNavigator.this.jbtnSortActionPerformed(paramActionEvent);
        }
      });
      add(this.jbtnSort);
    }
    this.m_bd = paramBrowsableEditableData;
    paramBrowsableEditableData.addBrowseListener(this);
    paramBrowsableEditableData.addStateListener(this);
  }

  public JNavigator(BrowsableEditableData paramBrowsableEditableData)
  {
    this(paramBrowsableEditableData, null, null, 0);
  }

  public JNavigator(BrowsableEditableData paramBrowsableEditableData, Vectorer paramVectorer, ComparatorCreator paramComparatorCreator)
  {
    this(paramBrowsableEditableData, paramVectorer, paramComparatorCreator, 0);
  }

  public void updateState(int paramInt)
  {
    if ((paramInt == 3) || (paramInt == 2))
    {
      if (this.jbtnFirst != null)
        this.jbtnFirst.setEnabled(false);
      if (this.jbtnPrev != null)
        this.jbtnPrev.setEnabled(false);
      if (this.jbtnNext != null)
        this.jbtnNext.setEnabled(false);
      if (this.jbtnLast != null)
        this.jbtnLast.setEnabled(false);
      if (this.jbtnRefresh != null)
        this.jbtnRefresh.setEnabled(true);
    }
  }

  public void updateIndex(int paramInt1, int paramInt2)
  {
    if ((paramInt1 >= 0) && (paramInt1 < paramInt2))
    {
      if (this.jbtnFirst != null)
        this.jbtnFirst.setEnabled(paramInt1 > 0);
      if (this.jbtnPrev != null)
        this.jbtnPrev.setEnabled(paramInt1 > 0);
      if (this.jbtnNext != null)
        this.jbtnNext.setEnabled(paramInt1 < paramInt2 - 1);
      if (this.jbtnLast != null)
        this.jbtnLast.setEnabled(paramInt1 < paramInt2 - 1);
      if (this.jbtnRefresh != null)
        this.jbtnRefresh.setEnabled(true);
    }
    else
    {
      if (this.jbtnFirst != null)
        this.jbtnFirst.setEnabled(false);
      if (this.jbtnPrev != null)
        this.jbtnPrev.setEnabled(false);
      if (this.jbtnNext != null)
        this.jbtnNext.setEnabled(false);
      if (this.jbtnLast != null)
        this.jbtnLast.setEnabled(false);
      if (this.jbtnRefresh != null)
        this.jbtnRefresh.setEnabled(false);
    }
  }

  private void jbtnSortActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      Comparator localComparator = JSort.showMessage(this, this.m_cc);
      if (localComparator != null)
        this.m_bd.sort(localComparator);
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nolistdata"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnFindActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      FindInfo localFindInfo = JFind.showMessage(this, this.m_LastFindInfo);
      if (localFindInfo != null)
      {
        this.m_LastFindInfo = localFindInfo;
        int i = this.m_bd.findNext(localFindInfo);
        if (i < 0)
        {
          MessageInf localMessageInf2 = new MessageInf(-67108864, LocalRes.getIntString("message.norecord"));
          localMessageInf2.show(this);
        }
        else
        {
          this.m_bd.moveTo(i);
        }
      }
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf1 = new MessageInf(-67108864, LocalRes.getIntString("message.nolistdata"), localBasicException);
      localMessageInf1.show(this);
    }
  }

  private void jbtnRefreshActionPerformed(ActionEvent paramActionEvent)
  {
    this.m_bd.actionReloadCurrent(this);
  }

  private void jbtnReloadActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.actionLoad();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.noreload"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnLastActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.moveLast();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nomove"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnFirstActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.moveFirst();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nomove"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnPrevActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.movePrev();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nomove"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnNextActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.moveNext();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nomove"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void initComponents()
  {
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.gui.JNavigator
 * JD-Core Version:    0.6.0
 */